package com.auto.autoapp.task

import com.auto.autoapp.step.clickCommentBtn
import com.auto.autoapp.step.exchangeVideo
import com.auto.autoapp.step.isLiveVideo
import com.auto.autoapp.step.sendComment
import com.auto.autoapp.step.toDyIndex
import com.ven.assists.AssistsCore
import com.ven.assists.stepper.Step
import com.ven.assists.stepper.StepCollector
import com.ven.assists.stepper.StepImpl
import kotlinx.coroutines.delay

/**
 * 视频评论
 * 1.跳转至首页
 * 2.点击评论按钮 -> 点击下方评论 -> 输入评论 ->发送
 * 3.滑动视频，重复步骤2
 */
class VideoCommentTask : StepImpl() {
    override fun onImpl(collector: StepCollector) {
        collector.next(1) {
            return@next toDyIndex()
        }.next(2) {
            val isLive = isLiveVideo()
            if (isLive.isSuccess) {
                return@next Step.get(3)
            }
            var click = clickCommentBtn()
            if (click.isSuccess) {
                delay(1000)
                var sendResult = sendComment("1")
                if (sendResult.isSuccess) {
                    AssistsCore.back()
                    delay(1000)
                }
            }
            return@next Step.get(3)
        }.next(3) {
            var exchangeResult = exchangeVideo()
            if (exchangeResult.isFailure) {
                return@next Step.none
            }
            val isLive = isLiveVideo()
            if (isLive.isSuccess) {
                return@next Step.repeat
            }

            return@next Step.get(2)
        }

    }

}